from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
from meiduo_mall import settings


def generic_verify_url(user_id,email):

    serializer = Serializer(secret_key=settings.SECRET_KEY,expires_in=3600)
    data = {
        'user_id':user_id,
        'email':email
    }

    token = serializer.dumps(data)

    return 'http://www.meiduo.site:8080/success_verify_email.html?token=%s'%token.decode()


def check_active_token(token):

    serializer = Serializer(secret_key=settings.SECRET_KEY, expires_in=3600)

    try:
        data = serializer.loads(token)

    except Exception:
        return None

    return data
